package com.mixsmart.commonweb.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicUpdate;

import com.mixsmart.commonweb.bean.ICreateTime;
import com.mixsmart.commonweb.bean.ISelfClassAssert;
import com.mixsmart.enums.YesNoType;

/**
 * 菜单--实体对象
 * @author lmq
 * @version 1.0
 * @since JDK版本大于等于1.6
 * 2016年1月26日
 */
@Entity
@Table(name="t_c_menu")
@DynamicUpdate(true)
public class TCMenu implements ISelfClassAssert<TCMenu>, ICreateTime, Cloneable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2270369919637511150L;

	private String id;
	
	private String name;
	
	private String parentId;
	
	/**
	 * 打开方式
	 */
	private String openModel;
	
	private Integer state = YesNoType.YES.getIndex();
	
	private String icon;
	
	private Integer sortNum = 0;
	
	/**
	 * URL资源ID（URL统一管理）
	 */
	private String urlResId;
	
	private Date createTime;
	
	/**
	 * 层级
	 */
	private Integer level = 0;
	
	/**
	 * 是否叶子节点
	 */
	private Boolean isLeaf = true;
	
	/**
	 * 资源URL(非持久字段)；临时变量
	 */
	private String url;
	
	public TCMenu() {
		
	}

	public TCMenu(String name, String parentId, String openModel, Integer sortNum, 
			Integer state, String icon, Integer level, Boolean isLeaf) {
		this.name = name;
		this.parentId = parentId;
		this.openModel = openModel;
		this.sortNum = sortNum;
		this.state = state;
		this.icon = icon;
		this.level = level;
		this.isLeaf = isLeaf;
	}
	
	public TCMenu(String name, String parentId, String openModel, Integer sortNum, Integer state,
			String icon, String urlResId, Integer level, Boolean isLeaf) {
		this.name = name;
		this.parentId = parentId;
		this.openModel = openModel;
		this.sortNum = sortNum;
		this.state = state;
		this.icon = icon;
		this.urlResId = urlResId;
		this.level = level;
		this.isLeaf = isLeaf;
	}

  /////getter and setter/////
	@Id
	@Column(name="id",length=50,nullable=false)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="name",length=255,nullable=false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="parent_id",length=50)
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Column(name="open_model",length=50)
	public String getOpenModel() {
		return openModel;
	}

	public void setOpenModel(String openModel) {
		this.openModel = openModel;
	}

	@Column(name="state")
	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Column(name="icon",length=255)
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Column(name="url_res_id",length=50)
	public String getUrlResId() {
		return urlResId;
	}

	public void setUrlResId(String urlResId) {
		this.urlResId = urlResId;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="create_time",updatable=false)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name="level_", nullable=false)
	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	@Column(name="is_leaf")
	public Boolean getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(Boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	@Column(name="sort_num")
	public Integer getSortNum() {
		return sortNum;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	@Transient
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Override
	public TCMenu clone() {
		TCMenu menu = null;
		try {
			menu = (TCMenu) super.clone();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return menu;
	}
	
	@Override
	public void assertValue(TCMenu menu) {
		if(null != menu) {
			this.icon = menu.getIcon();
			this.level = menu.getLevel();
			this.name = menu.getName();
			this.openModel = menu.getOpenModel();
			this.parentId = menu.getParentId();
			this.sortNum = menu.getSortNum();
			this.state = menu.getState();
			this.urlResId = menu.getUrlResId();
		}
	}
	
}
